package com.manage.function.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.manage.common.core.domain.entity.SysDept;
import com.manage.function.domain.vo.DeptInfo;
import com.manage.function.domain.vo.Expenditure;
import com.manage.system.mapper.SysDeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.manage.function.mapper.FunctionExpenseMapper;
import com.manage.function.domain.FunctionExpense;
import com.manage.function.service.IFunctionExpenseService;

import javax.annotation.Resource;

/**
 * 财务支出Service业务层处理
 *
 * @author jinghj
 * @date 2025-03-09
 */
@Service
public class FunctionExpenseServiceImpl implements IFunctionExpenseService
{
    @Autowired
    private FunctionExpenseMapper functionExpenseMapper;

    @Resource
    private SysDeptMapper sysDeptMapper;

    /**
     * 查询财务支出
     *
     * @param id 财务支出主键
     * @return 财务支出
     */
    @Override
    public FunctionExpense selectFunctionExpenseById(Long id)
    {
        return functionExpenseMapper.selectFunctionExpenseById(id);
    }

    /**
     * 查询财务支出列表
     *
     * @param functionExpense 财务支出
     * @return 财务支出
     */
    @Override
    public List<FunctionExpense> selectFunctionExpenseList(FunctionExpense functionExpense)
    {
        return functionExpenseMapper.selectFunctionExpenseList(functionExpense);
    }

    /**
     * 新增财务支出
     *
     * @param functionExpense 财务支出
     * @return 结果
     */
    @Override
    public int insertFunctionExpense(FunctionExpense functionExpense)
    {
        return functionExpenseMapper.insertFunctionExpense(functionExpense);
    }

    /**
     * 修改财务支出
     *
     * @param functionExpense 财务支出
     * @return 结果
     */
    @Override
    public int updateFunctionExpense(FunctionExpense functionExpense)
    {
        return functionExpenseMapper.updateFunctionExpense(functionExpense);
    }

    /**
     * 批量删除财务支出
     *
     * @param ids 需要删除的财务支出主键
     * @return 结果
     */
    @Override
    public int deleteFunctionExpenseByIds(Long[] ids)
    {
        return functionExpenseMapper.deleteFunctionExpenseByIds(ids);
    }

    /**
     * 删除财务支出信息
     *
     * @param id 财务支出主键
     * @return 结果
     */
    @Override
    public int deleteFunctionExpenseById(Long id)
    {
        return functionExpenseMapper.deleteFunctionExpenseById(id);
    }

    @Override
    public List<DeptInfo> selectUserAndDept() {
        SysDept sysDept = new SysDept();
        List<DeptInfo> deptInfos = new ArrayList<>();
        List<SysDept> sysDepts = sysDeptMapper.selectDeptList(sysDept);
        if (sysDepts != null && sysDepts.size() > 0) {
            for (SysDept dept : sysDepts) {
                DeptInfo deptInfo = new DeptInfo();
                deptInfo.setDeptId(dept.getDeptId());
                deptInfo.setDeptName(dept.getDeptName());
                deptInfos.add(deptInfo);
            }
        }
        return deptInfos;
    }

    @Override
    public List<Expenditure> countExpenditure(String month) {
        return functionExpenseMapper.countExpenditure(month);
    }
}
